package com.ecoolex.discount.sales.enums;

import com.ecoolex.discount.sales.entity.DiscountProduct;
import com.ecoolex.framework.common.EnumInterface;
import com.ecoolex.framework.common.util.Check;

public enum DiscountProductStatus implements EnumInterface<DiscountProductStatus, Integer> {
    EDITING(0, "编辑中"),
    ONLINE(1, "上线"),
    OFFLINE(2, "下线"),
    STOP_SELLING(3, "停止销售"),
    ;

    private int real;

    private String describe;

    private DiscountProductStatus(int real, String describe) {
        this.real = real;
        this.describe = describe;
    }

    @Override
    public Integer real() {
        return real;
    }

    @Override
    public String describe() {
        return describe;
    }

    public static DiscountProductStatus realValueOf(Integer real) {
        if (Check.notNull(real)) {
            for (DiscountProductStatus v : values()) {
                if (v.real().equals(real)) {
                    return v;
                }
            }
        }
        return null;
    }

    public static boolean canOnline(DiscountProduct product) {
        return EDITING.equal(product.getStatus()) || OFFLINE.equal(product.getStatus())|| STOP_SELLING.equal(product.getStatus());
    }

    public static boolean canOffline(DiscountProduct product) {
        return ONLINE.equal(product.getStatus());
    }

    public static boolean canDel(DiscountProduct product) {
        return canOnline(product);
    }
}
